package com.excilys.capicsoubank.webservices.soap.impl;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.excilys.capicsoubank.dto.Transfer;
import com.excilys.capicsoubank.services.TransactionService;
import com.excilys.capicsoubank.webservices.exception.NegativeBalanceException;
import com.excilys.capicsoubank.webservices.soap.TransferWebService;

@Component("transferWebServiceImpl")
@WebService(endpointInterface = "com.excilys.capicsoubank.webservices.soap.TransferWebService")
public class TransferWebServiceImpl implements TransferWebService {

	@Autowired
	private TransactionService transactionService;

	@Override
	public void transfer(Transfer transfer) throws NegativeBalanceException {
		try {
			transactionService.transferBetweenAccounts(
					transfer.getAccountSourceId(),
					transfer.getAccountDestinationId(), transfer.getAmount());
		} catch (com.excilys.capicsoubank.exception.NegativeBalanceException e) {
			throw new NegativeBalanceException(e);
		}
	}
}
